package com.itheima.config;

import com.itheima.CSM_bacK.aacMapper.MemberMapper;
import com.itheima.pojo.Entity.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

@Component
public class MyUserDetial implements UserDetailsService {
    @Autowired
    private MemberMapper memberMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Member kk = memberMapper.getMemberByuserName(username);
        if (kk == null) {
            throw new UsernameNotFoundException(username);
        }
        Set<String> kks = memberMapper.getSetAuthorityByUsername(username);
        Set<GrantedAuthority> sset = new HashSet<>();
        for (String s : kks) {
            sset.add(()->s);
        }
        return new User(username,kk.getPassword(),sset);
    }
}
